package com.suncaper.wcss.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suncaper.wcss.model.domain.OrganizationLevel;
import com.suncaper.wcss.mapper.OrganizationLevelMapper;
import com.suncaper.wcss.service.OrganizationLevelService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author lxp
 * @since 2021-11-16
 */
@Service
public class OrganizationLevelServiceImpl extends ServiceImpl<OrganizationLevelMapper, OrganizationLevel> implements OrganizationLevelService {

    @Override
    public List<OrganizationLevel> queryList(Integer type, String sn) {


        QueryWrapper<OrganizationLevel> wrapper = new QueryWrapper<>();
        if(Objects.nonNull(type)){
            wrapper.lambda().eq(OrganizationLevel::getOrganizationTypeId,type);
        }
        if(Objects.nonNull(sn)){
            QueryWrapper<OrganizationLevel> levelQueryWrapper = new QueryWrapper<>();
            levelQueryWrapper.lambda().eq(OrganizationLevel::getSn,sn);
            OrganizationLevel selectOne = baseMapper.selectOne(levelQueryWrapper);
            wrapper.lambda().eq(OrganizationLevel::getParentId,selectOne.getOrganizationId());
        }

        List<OrganizationLevel> levels = baseMapper.selectList(wrapper);
        return levels;
    }
}
